{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "延安油田标签传播算法半监督.ipynb",
      "provenance": [],
      "toc_visible": true,
      "authorship_tag": "ABX9TyN+fXTtMN9tjGyL0kxIvkPK",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/sunyingjian/-Logging-related-network/blob/master/%E5%BB%B6%E5%AE%89%E6%B2%B9%E7%94%B0%E6%A0%87%E7%AD%BE%E4%BC%A0%E6%92%AD%E7%AE%97%E6%B3%95%E5%8D%8A%E7%9B%91%E7%9D%A3.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Cqy3vXXOMI06",
        "colab_type": "text"
      },
      "source": [
        "### <font size=5px color=\"red\">✦ *Google Colab 突破90分钟自动断开:</font>\n",
        "<p><font size=3px > 每60分钟自动运行代码以刷新90分钟断开限制. 打开 developer-settings (在你的浏览器) 快速健 Ctrl+Shift+I 然后按console 输入以下代码 Enter. ( mac 按 Option+Command+I)</p><b>复制以下隐藏代码粉贴在浏览器console！！不要关闭浏览器以免失效</b>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3Z8cK8h2Avbv",
        "colab_type": "text"
      },
      "source": [
        "<code>function ClickConnect(){\n",
        "console.log(\"Working\"); \n",
        "document.querySelector(\"colab-connect-button\").click() \n",
        "}setInterval(ClickConnect,6000)</code>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jtClEMAMLVHw",
        "colab_type": "code",
        "cellView": "both",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "d59c975c-87fb-43ba-8df3-29eb88b3857c"
      },
      "source": [
        "#@markdown <h3>← 输入了代码后运行以防止断开</h>\n",
        "\n",
        "\n",
        "import IPython\n",
        "from google.colab import output\n",
        "\n",
        "display(IPython.display.Javascript('''\n",
        " function ClickConnect(){\n",
        "   btn = document.querySelector(\"colab-connect-button\")\n",
        "   if (btn != null){\n",
        "     console.log(\"Click colab-connect-button\"); \n",
        "     btn.click() \n",
        "     }\n",
        "   \n",
        "   btn = document.getElementById('ok')\n",
        "   if (btn != null){\n",
        "     console.log(\"Click reconnect\"); \n",
        "     btn.click() \n",
        "     }\n",
        "  }\n",
        "  \n",
        "setInterval(ClickConnect,60000)\n",
        "'''))\n",
        "\n",
        "print(\"Done.\")"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "application/javascript": [
              "\n",
              " function ClickConnect(){\n",
              "   btn = document.querySelector(\"colab-connect-button\")\n",
              "   if (btn != null){\n",
              "     console.log(\"Click colab-connect-button\"); \n",
              "     btn.click() \n",
              "     }\n",
              "   \n",
              "   btn = document.getElementById('ok')\n",
              "   if (btn != null){\n",
              "     console.log(\"Click reconnect\"); \n",
              "     btn.click() \n",
              "     }\n",
              "  }\n",
              "  \n",
              "setInterval(ClickConnect,60000)\n"
            ],
            "text/plain": [
              "<IPython.core.display.Javascript object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "Done.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3rOB-pyy34rB",
        "colab_type": "text"
      },
      "source": [
        "#准备数据"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oF-1Sg_w36eT",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        },
        "outputId": "96d86abc-d491-4392-b98c-1f50aa7d7c80"
      },
      "source": [
        "! git clone https://github.com/sunyingjian/numpy-.git\n",
        "! git clone https://github.com/seg/tutorials-2016.git"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Cloning into 'numpy-'...\n",
            "remote: Enumerating objects: 89, done.\u001b[K\n",
            "Unpacking objects:   1% (1/89)   \rUnpacking objects:   2% (2/89)   \rUnpacking objects:   3% (3/89)   \rUnpacking objects:   4% (4/89)   \rUnpacking objects:   5% (5/89)   \rUnpacking objects:   6% (6/89)   \rUnpacking objects:   7% (7/89)   \rUnpacking objects:   8% (8/89)   \rUnpacking objects:  10% (9/89)   \rUnpacking objects:  11% (10/89)   \rUnpacking objects:  12% (11/89)   \rUnpacking objects:  13% (12/89)   \rUnpacking objects:  14% (13/89)   \rUnpacking objects:  15% (14/89)   \rUnpacking objects:  16% (15/89)   \rUnpacking objects:  17% (16/89)   \rUnpacking objects:  19% (17/89)   \rUnpacking objects:  20% (18/89)   \rUnpacking objects:  21% (19/89)   \rUnpacking objects:  22% (20/89)   \rUnpacking objects:  23% (21/89)   \rUnpacking objects:  24% (22/89)   \rUnpacking objects:  25% (23/89)   \rUnpacking objects:  26% (24/89)   \rUnpacking objects:  28% (25/89)   \rUnpacking objects:  29% (26/89)   \rUnpacking objects:  30% (27/89)   \rUnpacking objects:  31% (28/89)   \rUnpacking objects:  32% (29/89)   \rUnpacking objects:  33% (30/89)   \rUnpacking objects:  34% (31/89)   \rUnpacking objects:  35% (32/89)   \rUnpacking objects:  37% (33/89)   \rUnpacking objects:  38% (34/89)   \rUnpacking objects:  39% (35/89)   \rUnpacking objects:  40% (36/89)   \rUnpacking objects:  41% (37/89)   \rUnpacking objects:  42% (38/89)   \rUnpacking objects:  43% (39/89)   \rUnpacking objects:  44% (40/89)   \rUnpacking objects:  46% (41/89)   \rUnpacking objects:  47% (42/89)   \rUnpacking objects:  48% (43/89)   \rUnpacking objects:  49% (44/89)   \rUnpacking objects:  50% (45/89)   \rUnpacking objects:  51% (46/89)   \rUnpacking objects:  52% (47/89)   \rUnpacking objects:  53% (48/89)   \rUnpacking objects:  55% (49/89)   \rUnpacking objects:  56% (50/89)   \rUnpacking objects:  57% (51/89)   \rUnpacking objects:  58% (52/89)   \rUnpacking objects:  59% (53/89)   \rUnpacking objects:  60% (54/89)   \rUnpacking objects:  61% (55/89)   \rUnpacking objects:  62% (56/89)   \rUnpacking objects:  64% (57/89)   \rUnpacking objects:  65% (58/89)   \rUnpacking objects:  66% (59/89)   \rUnpacking objects:  67% (60/89)   \rUnpacking objects:  68% (61/89)   \rUnpacking objects:  69% (62/89)   \rUnpacking objects:  70% (63/89)   \rUnpacking objects:  71% (64/89)   \rUnpacking objects:  73% (65/89)   \rUnpacking objects:  74% (66/89)   \rUnpacking objects:  75% (67/89)   \rUnpacking objects:  76% (68/89)   \rUnpacking objects:  77% (69/89)   \rUnpacking objects:  78% (70/89)   \rUnpacking objects:  79% (71/89)   \rremote: Total 89 (delta 0), reused 0 (delta 0), pack-reused 89\u001b[K\n",
            "Unpacking objects: 100% (89/89), done.\n",
            "Cloning into 'tutorials-2016'...\n",
            "remote: Enumerating objects: 161, done.\u001b[K\n",
            "remote: Total 161 (delta 0), reused 0 (delta 0), pack-reused 161\u001b[K\n",
            "Receiving objects: 100% (161/161), 16.86 MiB | 23.27 MiB/s, done.\n",
            "Resolving deltas: 100% (64/64), done.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TWm92l7z3_mS",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 124
        },
        "outputId": "2df476fb-fa42-46ae-d16a-0063b70aa246"
      },
      "source": [
        "import os\n",
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n",
            "\n",
            "Enter your authorization code:\n",
            "··········\n",
            "Mounted at /content/drive\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_darwkxd8M4a",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import numpy as np\n",
        "import pandas as pd \n",
        "import matplotlib.pyplot as plt"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ohsoY40PEy2_",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 407
        },
        "outputId": "98e410e4-3d85-4e62-a16c-da80e6e09929"
      },
      "source": [
        "df_data_1 = pd.read_csv('/content/numpy-/半监督数据集/有标签数据集.csv')\n",
        "df_data_2 = pd.read_csv('/content/numpy-/半监督数据集/无标签数据集.csv')\n",
        "df_data_1"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>AC</th>\n",
              "      <th>CAL</th>\n",
              "      <th>GR</th>\n",
              "      <th>K</th>\n",
              "      <th>RD</th>\n",
              "      <th>SP</th>\n",
              "      <th>Core Lithology</th>\n",
              "      <th>Unnamed: 7</th>\n",
              "      <th>Unnamed: 8</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0.038756</td>\n",
              "      <td>0.026970</td>\n",
              "      <td>0.094776</td>\n",
              "      <td>0.112543</td>\n",
              "      <td>0.001420</td>\n",
              "      <td>0.614504</td>\n",
              "      <td>5</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0.347382</td>\n",
              "      <td>0.090194</td>\n",
              "      <td>0.145150</td>\n",
              "      <td>0.202335</td>\n",
              "      <td>0.002744</td>\n",
              "      <td>0.339568</td>\n",
              "      <td>7</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0.218400</td>\n",
              "      <td>0.059510</td>\n",
              "      <td>0.252165</td>\n",
              "      <td>0.711295</td>\n",
              "      <td>0.003874</td>\n",
              "      <td>0.918567</td>\n",
              "      <td>3</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0.366064</td>\n",
              "      <td>0.082147</td>\n",
              "      <td>0.149304</td>\n",
              "      <td>0.201731</td>\n",
              "      <td>0.003290</td>\n",
              "      <td>0.343180</td>\n",
              "      <td>7</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0.291877</td>\n",
              "      <td>0.079981</td>\n",
              "      <td>0.141782</td>\n",
              "      <td>0.289309</td>\n",
              "      <td>0.003455</td>\n",
              "      <td>0.344605</td>\n",
              "      <td>7</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>361</th>\n",
              "      <td>0.016947</td>\n",
              "      <td>0.138827</td>\n",
              "      <td>0.118400</td>\n",
              "      <td>0.358567</td>\n",
              "      <td>0.281687</td>\n",
              "      <td>0.302936</td>\n",
              "      <td>6</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>362</th>\n",
              "      <td>0.131043</td>\n",
              "      <td>0.069016</td>\n",
              "      <td>0.029354</td>\n",
              "      <td>0.060197</td>\n",
              "      <td>0.282093</td>\n",
              "      <td>0.253809</td>\n",
              "      <td>3</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>363</th>\n",
              "      <td>0.036182</td>\n",
              "      <td>0.032010</td>\n",
              "      <td>0.030090</td>\n",
              "      <td>0.071069</td>\n",
              "      <td>0.359737</td>\n",
              "      <td>0.435486</td>\n",
              "      <td>5</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>364</th>\n",
              "      <td>0.014562</td>\n",
              "      <td>0.127332</td>\n",
              "      <td>0.035014</td>\n",
              "      <td>0.178579</td>\n",
              "      <td>0.803566</td>\n",
              "      <td>0.311641</td>\n",
              "      <td>6</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>365</th>\n",
              "      <td>0.014427</td>\n",
              "      <td>0.134185</td>\n",
              "      <td>0.033460</td>\n",
              "      <td>0.186430</td>\n",
              "      <td>0.891134</td>\n",
              "      <td>0.311652</td>\n",
              "      <td>6</td>\n",
              "      <td>NaN</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>366 rows × 9 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "           AC       CAL        GR  ...  Core Lithology  Unnamed: 7  Unnamed: 8\n",
              "0    0.038756  0.026970  0.094776  ...               5         NaN         NaN\n",
              "1    0.347382  0.090194  0.145150  ...               7         NaN         NaN\n",
              "2    0.218400  0.059510  0.252165  ...               3         NaN         NaN\n",
              "3    0.366064  0.082147  0.149304  ...               7         NaN         NaN\n",
              "4    0.291877  0.079981  0.141782  ...               7         NaN         NaN\n",
              "..        ...       ...       ...  ...             ...         ...         ...\n",
              "361  0.016947  0.138827  0.118400  ...               6         NaN         NaN\n",
              "362  0.131043  0.069016  0.029354  ...               3         NaN         NaN\n",
              "363  0.036182  0.032010  0.030090  ...               5         NaN         NaN\n",
              "364  0.014562  0.127332  0.035014  ...               6         NaN         NaN\n",
              "365  0.014427  0.134185  0.033460  ...               6         NaN         NaN\n",
              "\n",
              "[366 rows x 9 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "SBYgxskpIbl9",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 407
        },
        "outputId": "6c9e10b6-d322-49a6-accc-2addfc7bd9f7"
      },
      "source": [
        "df_data_2"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>AC</th>\n",
              "      <th>CAL</th>\n",
              "      <th>GR</th>\n",
              "      <th>K</th>\n",
              "      <th>RD</th>\n",
              "      <th>SP</th>\n",
              "      <th>Core Lithology</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0.029102</td>\n",
              "      <td>0.031789</td>\n",
              "      <td>0.026724</td>\n",
              "      <td>0.202335</td>\n",
              "      <td>0.078986</td>\n",
              "      <td>0.333754</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>0.032883</td>\n",
              "      <td>0.033469</td>\n",
              "      <td>0.030592</td>\n",
              "      <td>0.203141</td>\n",
              "      <td>0.076064</td>\n",
              "      <td>0.333669</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>0.034385</td>\n",
              "      <td>0.037006</td>\n",
              "      <td>0.032359</td>\n",
              "      <td>0.200121</td>\n",
              "      <td>0.074503</td>\n",
              "      <td>0.333619</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>0.243816</td>\n",
              "      <td>0.143381</td>\n",
              "      <td>0.086581</td>\n",
              "      <td>0.290115</td>\n",
              "      <td>0.017649</td>\n",
              "      <td>0.094025</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>0.248043</td>\n",
              "      <td>0.146786</td>\n",
              "      <td>0.084643</td>\n",
              "      <td>0.283874</td>\n",
              "      <td>0.017286</td>\n",
              "      <td>0.090554</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3340</th>\n",
              "      <td>0.012092</td>\n",
              "      <td>0.067866</td>\n",
              "      <td>0.007657</td>\n",
              "      <td>0.077713</td>\n",
              "      <td>0.181798</td>\n",
              "      <td>0.348797</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3341</th>\n",
              "      <td>0.011831</td>\n",
              "      <td>0.069989</td>\n",
              "      <td>0.007606</td>\n",
              "      <td>0.081135</td>\n",
              "      <td>0.206839</td>\n",
              "      <td>0.348560</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3342</th>\n",
              "      <td>0.011533</td>\n",
              "      <td>0.070121</td>\n",
              "      <td>0.009591</td>\n",
              "      <td>0.081337</td>\n",
              "      <td>0.250115</td>\n",
              "      <td>0.348470</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3343</th>\n",
              "      <td>0.008903</td>\n",
              "      <td>0.069325</td>\n",
              "      <td>0.010596</td>\n",
              "      <td>0.081135</td>\n",
              "      <td>0.281774</td>\n",
              "      <td>0.348340</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3344</th>\n",
              "      <td>0.003230</td>\n",
              "      <td>0.070210</td>\n",
              "      <td>0.012674</td>\n",
              "      <td>0.080129</td>\n",
              "      <td>0.329088</td>\n",
              "      <td>0.348228</td>\n",
              "      <td>NaN</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>3345 rows × 7 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "            AC       CAL        GR  ...        RD        SP  Core Lithology\n",
              "0     0.029102  0.031789  0.026724  ...  0.078986  0.333754             NaN\n",
              "1     0.032883  0.033469  0.030592  ...  0.076064  0.333669             NaN\n",
              "2     0.034385  0.037006  0.032359  ...  0.074503  0.333619             NaN\n",
              "3     0.243816  0.143381  0.086581  ...  0.017649  0.094025             NaN\n",
              "4     0.248043  0.146786  0.084643  ...  0.017286  0.090554             NaN\n",
              "...        ...       ...       ...  ...       ...       ...             ...\n",
              "3340  0.012092  0.067866  0.007657  ...  0.181798  0.348797             NaN\n",
              "3341  0.011831  0.069989  0.007606  ...  0.206839  0.348560             NaN\n",
              "3342  0.011533  0.070121  0.009591  ...  0.250115  0.348470             NaN\n",
              "3343  0.008903  0.069325  0.010596  ...  0.281774  0.348340             NaN\n",
              "3344  0.003230  0.070210  0.012674  ...  0.329088  0.348228             NaN\n",
              "\n",
              "[3345 rows x 7 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 5
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tCPRJl3pIjqv",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 311
        },
        "outputId": "218a01bb-35fd-4167-e5e1-56cf23b5865b"
      },
      "source": [
        "X_s= df_data_1.iloc[:,:6].values\n",
        "y_s = df_data_1['Core Lithology'].values\n",
        "X_t= df_data_2.iloc[:,:6].values\n",
        "y_s"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([5, 7, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 3, 7, 3, 3, 3, 7, 7, 3, 2,\n",
              "       2, 7, 2, 3, 3, 7, 3, 7, 7, 7, 2, 7, 3, 2, 3, 2, 4, 3, 4, 3, 3, 7,\n",
              "       7, 7, 7, 7, 7, 2, 7, 2, 3, 3, 3, 7, 2, 7, 3, 2, 7, 4, 2, 7, 3, 3,\n",
              "       3, 3, 7, 4, 4, 3, 2, 7, 2, 4, 4, 3, 2, 7, 2, 2, 4, 3, 2, 2, 2, 2,\n",
              "       3, 2, 4, 4, 2, 4, 2, 3, 7, 3, 2, 3, 7, 2, 3, 2, 3, 3, 7, 3, 3, 3,\n",
              "       3, 3, 3, 3, 7, 2, 2, 2, 4, 2, 2, 2, 2, 2, 3, 7, 3, 2, 1, 2, 3, 3,\n",
              "       2, 3, 3, 5, 3, 7, 3, 3, 7, 3, 3, 4, 5, 3, 7, 2, 7, 7, 3, 2, 3, 3,\n",
              "       3, 3, 7, 7, 2, 7, 1, 1, 3, 1, 3, 3, 7, 1, 7, 3, 3, 3, 7, 3, 7, 7,\n",
              "       3, 1, 3, 7, 7, 5, 1, 2, 3, 7, 2, 2, 3, 7, 4, 7, 7, 5, 7, 2, 7, 3,\n",
              "       7, 3, 7, 3, 2, 7, 2, 7, 7, 1, 2, 2, 7, 7, 1, 7, 2, 3, 2, 3, 1, 7,\n",
              "       7, 1, 2, 7, 1, 7, 2, 2, 7, 1, 5, 4, 5, 2, 2, 7, 2, 2, 5, 1, 3, 7,\n",
              "       7, 5, 7, 2, 6, 2, 7, 1, 7, 2, 5, 7, 5, 2, 7, 7, 2, 7, 7, 7, 4, 2,\n",
              "       7, 7, 7, 2, 4, 2, 7, 7, 6, 1, 7, 1, 2, 3, 3, 7, 4, 1, 4, 5, 2, 5,\n",
              "       2, 2, 5, 5, 2, 5, 5, 6, 2, 2, 2, 3, 2, 5, 6, 5, 2, 5, 7, 5, 5, 5,\n",
              "       5, 5, 5, 1, 5, 1, 7, 2, 5, 5, 7, 5, 5, 7, 5, 5, 5, 5, 6, 5, 5, 5,\n",
              "       2, 5, 2, 5, 7, 5, 6, 7, 5, 5, 7, 6, 5, 5, 2, 6, 5, 4, 3, 5, 3, 5,\n",
              "       6, 2, 5, 7, 5, 6, 3, 5, 5, 6, 3, 5, 6, 6])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "dX1awHeAFH2p",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "labels_s = np.copy(y_s)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YTkxWxjbLh8u",
        "colab_type": "text"
      },
      "source": [
        "#标签传播算法"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TmzzTEj5JaoF",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 52
        },
        "outputId": "632c7b09-bde8-4885-c05a-2b4f8f51d0c3"
      },
      "source": [
        "from sklearn.semi_supervised import LabelPropagation\n",
        "laber_prop_model = LabelPropagation()\n",
        "laber_prop_model.fit(X_s,y_s)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "LabelPropagation(gamma=20, kernel='rbf', max_iter=1000, n_jobs=None,\n",
              "                 n_neighbors=7, tol=0.001)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 9
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aUeucdyzFTUP",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "fe94e751-07ab-4058-8e53-56858d38f88a"
      },
      "source": [
        "#对没有标签的数据集使用LPA算法打上标签\n",
        "Y_pred2 = laber_prop_model.predict(X_t)\n",
        "print(Y_pred2)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[5 5 5 ... 5 5 5]\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MLrIsZInKUWw",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 242
        },
        "outputId": "5b02f8e3-4be5-4add-ed01-4dc90f1839a2"
      },
      "source": [
        "X=np.append(X_s,X_t,axis=0)\n",
        "X"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([[0.03875584, 0.02696967, 0.09477602, 0.11254278, 0.00141979,\n",
              "        0.61450399],\n",
              "       [0.34738218, 0.09019365, 0.14515003, 0.20233541, 0.00274352,\n",
              "        0.33956822],\n",
              "       [0.2184003 , 0.05951012, 0.25216485, 0.71129454, 0.00387403,\n",
              "        0.91856718],\n",
              "       ...,\n",
              "       [0.01153279, 0.07012114, 0.00959134, 0.08133682, 0.25011533,\n",
              "        0.34846983],\n",
              "       [0.00890256, 0.06932532, 0.01059554, 0.08113549, 0.28177415,\n",
              "        0.34834024],\n",
              "       [0.00323044, 0.07020957, 0.01267433, 0.08012885, 0.32908795,\n",
              "        0.34822757]])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "w74187hvKqdl",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "bf29c9ba-21a0-4101-e64a-5e866e3cba5b"
      },
      "source": [
        "Y=np.append(y_s,Y_pred2,axis=0)\n",
        "Y"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "array([5, 7, 3, ..., 5, 5, 5])"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 11
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Yj0BMwVlfa1-",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "Y_1=np.append(Y_pred2,y_s,axis=0)\n",
        "true_data = pd.read_csv('/content/numpy-/延安油田总数居.csv')\n",
        "Y_true = true_data['Core Lithology'].values"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tM-XNv36fPsj",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "faf39be7-5bbf-4f3d-8757-5c210e001e9a"
      },
      "source": [
        "from sklearn import metrics\n",
        "print('标签传播Accuracy : %f' % (metrics.accuracy_score(Y_1, Y_true)))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "标签传播Accuracy : 0.552412\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "lcAK3bPYLpSc",
        "colab_type": "text"
      },
      "source": [
        "#随机森林"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MZac5JmhK08S",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from sklearn.model_selection import train_test_split\n",
        "X_train, X_test, y_train, y_test = train_test_split(\n",
        "        X, Y, test_size=0.2, random_state=42)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VHyI4ibQLOAk",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 587
        },
        "outputId": "65d370ac-0dc1-4efe-f135-b26d1de8071c"
      },
      "source": [
        "from sklearn.ensemble import RandomForestClassifier\n",
        "from sklearn import metrics\n",
        "\n",
        "rfmodel = RandomForestClassifier()\n",
        "rfmodel.fit(X_train,y_train)\n",
        "print('model')\n",
        "print(rfmodel)\n",
        "\n",
        "ypredrf1 = rfmodel.predict(X_test)\n",
        "print('confusion matrix')\n",
        "print(metrics.confusion_matrix(y_test, ypredrf1))\n",
        "print('classification report')\n",
        "print(metrics.classification_report(y_test, ypredrf1))\n",
        "print('Accuracy : %f' % (metrics.accuracy_score(y_test, ypredrf1)))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "model\n",
            "RandomForestClassifier(bootstrap=True, ccp_alpha=0.0, class_weight=None,\n",
            "                       criterion='gini', max_depth=None, max_features='auto',\n",
            "                       max_leaf_nodes=None, max_samples=None,\n",
            "                       min_impurity_decrease=0.0, min_impurity_split=None,\n",
            "                       min_samples_leaf=1, min_samples_split=2,\n",
            "                       min_weight_fraction_leaf=0.0, n_estimators=100,\n",
            "                       n_jobs=None, oob_score=False, random_state=None,\n",
            "                       verbose=0, warm_start=False)\n",
            "confusion matrix\n",
            "[[  3   0   4   0   0   0   0]\n",
            " [  0  75   8   0   0   0   7]\n",
            " [  0   4 265   1   2   0   5]\n",
            " [  0   1   1   0   0   0   2]\n",
            " [  0   0   7   0 115   0   0]\n",
            " [  0   0   0   0   0   3   1]\n",
            " [  1   2   8   0   0   0 228]]\n",
            "classification report\n",
            "              precision    recall  f1-score   support\n",
            "\n",
            "           1       0.75      0.43      0.55         7\n",
            "           2       0.91      0.83      0.87        90\n",
            "           3       0.90      0.96      0.93       277\n",
            "           4       0.00      0.00      0.00         4\n",
            "           5       0.98      0.94      0.96       122\n",
            "           6       1.00      0.75      0.86         4\n",
            "           7       0.94      0.95      0.95       239\n",
            "\n",
            "    accuracy                           0.93       743\n",
            "   macro avg       0.78      0.70      0.73       743\n",
            "weighted avg       0.92      0.93      0.92       743\n",
            "\n",
            "Accuracy : 0.927322\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VB3E6bCoLsWH",
        "colab_type": "text"
      },
      "source": [
        "#只使用有标签数据做随机森林"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pU58wc2bLwu0",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from sklearn.model_selection import train_test_split\n",
        "X_train_o, X_test_o, y_train_o, y_test_o = train_test_split(\n",
        "        X_s, y_s, test_size=0.2, random_state=42)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_n7BpsuiL8kK",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 587
        },
        "outputId": "970db67d-3da7-46c3-f8a6-e2afbac57829"
      },
      "source": [
        "from sklearn.ensemble import RandomForestClassifier\n",
        "from sklearn import metrics\n",
        "\n",
        "rfmodel = RandomForestClassifier()\n",
        "rfmodel.fit(X_train_o,y_train_o)\n",
        "print('model')\n",
        "print(rfmodel)\n",
        "\n",
        "ypredrf1 = rfmodel.predict(X_test_o)\n",
        "print('confusion matrix')\n",
        "print(metrics.confusion_matrix(y_test_o, ypredrf1))\n",
        "print('classification report')\n",
        "print(metrics.classification_report(y_test_o, ypredrf1))\n",
        "print('Accuracy : %f' % (metrics.accuracy_score(y_test_o, ypredrf1)))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "model\n",
            "RandomForestClassifier(bootstrap=True, ccp_alpha=0.0, class_weight=None,\n",
            "                       criterion='gini', max_depth=None, max_features='auto',\n",
            "                       max_leaf_nodes=None, max_samples=None,\n",
            "                       min_impurity_decrease=0.0, min_impurity_split=None,\n",
            "                       min_samples_leaf=1, min_samples_split=2,\n",
            "                       min_weight_fraction_leaf=0.0, n_estimators=100,\n",
            "                       n_jobs=None, oob_score=False, random_state=None,\n",
            "                       verbose=0, warm_start=False)\n",
            "confusion matrix\n",
            "[[ 1  1  0  0  0  0  0]\n",
            " [ 0 14  1  0  0  0  1]\n",
            " [ 0  0 14  0  0  0  0]\n",
            " [ 0  3  0  3  0  0  0]\n",
            " [ 0  0  0  0 12  0  0]\n",
            " [ 0  0  0  0  0  1  0]\n",
            " [ 0  0  0  0  1  0 22]]\n",
            "classification report\n",
            "              precision    recall  f1-score   support\n",
            "\n",
            "           1       1.00      0.50      0.67         2\n",
            "           2       0.78      0.88      0.82        16\n",
            "           3       0.93      1.00      0.97        14\n",
            "           4       1.00      0.50      0.67         6\n",
            "           5       0.92      1.00      0.96        12\n",
            "           6       1.00      1.00      1.00         1\n",
            "           7       0.96      0.96      0.96        23\n",
            "\n",
            "    accuracy                           0.91        74\n",
            "   macro avg       0.94      0.83      0.86        74\n",
            "weighted avg       0.91      0.91      0.90        74\n",
            "\n",
            "Accuracy : 0.905405\n"
          ],
          "name": "stdout"
        }
      ]
    }
  ]
}
